package mymac.com.app;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by mymac on 2017/3/15.
 */

public class SharedPreferencesUtil {

    public static final String TAG = "TEST";

    // preference写入器
    private static SharedPreferences sp;
    private static SharedPreferences.Editor editor;
    private static SharedPreferencesUtil sharedPreferencesutil;

    public SharedPreferencesUtil(Context context){
        sp= context.getSharedPreferences(TAG,Context.MODE_PRIVATE);
        editor=sp.edit();
    }

    public static SharedPreferencesUtil getInstance(Context context){
        if (sharedPreferencesutil==null){
            sharedPreferencesutil=new SharedPreferencesUtil(context);
        }
        return  sharedPreferencesutil;
    }

    public void putSP(String key,String value){
        editor.putString(key,value);
        editor.commit();
    }

    public String getSP(String key){
        return sp.getString(key,"");
    }

    public void removeSP(String key){
        editor.remove(key);
        editor.commit();
    }

}
